package com.atguigu.cloudalibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class FlowLimitController {
    @GetMapping(value = "/test1")
    public String test1(){
//        try {
//            TimeUnit.MILLISECONDS.sleep(1000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        int age=10/0;
        System.out.println((new Date()).toString());
        return "test1";
    }
    @GetMapping(value = "/test2")
    public String test2(){return "test2";}

    @GetMapping(value = "/testHotkey")
    @SentinelResource(value = "testHotkey",//这里value随便写
            blockHandler = "deal_testHotkey"
    //如果某个资源违背了sentinel配的热点规则,就交由blockHandler指定的方法处理
    )
    public String testHotkey(//两个参数p1,p2都是可传可不传
            @RequestParam(value = "p1",required = false)String p1,
            @RequestParam(value = "p1",required = false)String p2){
        return "*-*-*-*-*-**-*testHotkey()";
    }
    public String deal_testHotkey(String p1, String p2, BlockException e){
        return "deal_testHotkey-----------/(ㄒoㄒ)/~~";
    }
}
